﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BL.BetterControls
{
    [ToolboxData("<{0}:_ZurbTabsContainer runat=server></{0}:_ZurbTabsContainer>")]
    public class _ZurbTabsContainer : Panel
    {
        _ZurbTab tabControl = null;

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Ul;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            tabControl = (_ZurbTab)Parent;
            Attributes["class"] = "tabs-content";
        }


        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            foreach (Control control in this.Controls)
            {
                if (control.Visible)
                {

                    if (control is _ZurbTabItem)
                    {
                        if (control.ID.EndsWith("Tab") == false)
                        {
                           // throw new ArgumentException("The Id of the _ZurbTabItem must end with Tab for JQuery functions", "ID");
                        }

                        if (tabControl.AddTab((_ZurbTabItem)control))
                        {
                            ((_ZurbTabItem)control).Attributes["class"] = "active";
                        }
                        else
                        {
                            ((_ZurbTabItem)control).Attributes.Remove("class");
                        }
                    }
                }
            }
        }
    }
}
